#ifndef FRUIT_H_
#define FRUIT_H_
#include <string>
#include <iostream>
using namespace std;
#include <algorithm>

class Fruit{
friend ostream& operator << (ostream& out, const Fruit& rhs);
private:
	string		name;
	double		price;
public:
	Fruit(const string& name, double price);
	double getPrice() const { return this->price; } 

	const string& getName() const { return this->name; }
};


Fruit::Fruit(const string& name, double price)
	:name(name),
	price(price)
{

}

ostream& operator << (ostream& out, const Fruit& rhs)
{
	out << rhs.name << "\t" << rhs.price << endl;
	return out;
}

class Basket{
private:
	vector<Fruit> fruits;
	Basket();
	static Basket* instance;
public:
	static Basket* getInstance();
	void insertFruit(const Fruit& fruit);
	void removeFruit(const Fruit& fruit);	
	void fruitSort();
	void print() const;
};
void Basket::print() const
{
	for(vector<Fruit>::const_iterator it = fruits.cbegin(); it != fruits.cend(); it++){
		cout << *it;
	}
}
Basket* Basket::instance = 0;
Basket::Basket()
{

}
Basket* Basket::getInstance()
{
	if(0 == instance)
		instance = new Basket();
	return instance;
}
bool cmp(const Fruit& lhs, const Fruit& rhs)
{
	return lhs.getPrice() > rhs.getPrice();
}
void Basket::insertFruit(const Fruit& fruit)
{
	fruits.push_back(fruit);
}

void Basket::removeFruit(const Fruit& fruit)
{
	for(vector<Fruit>::iterator it = fruits.begin(); it != fruits.end();){
		if(it->getName() == fruit.getName()){
			fruits.erase(it);
		}else{
			it++;
		}
	}
}

void Basket::fruitSort()
{
	sort(fruits.begin(), fruits.end(), cmp);
}

#endif
